Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
How can I remove ":" from the elements of array

I am Trying to convert the array [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ] to [ '900', '940', '950', '1100', '1500', '1800' ] in javascript.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can do it in this way:-

let oldArray = ['9:00', '9:40', '9:50', '11:00', '15:00', '18:00'];
let newArray = oldArray.map(elem => elem.replace(':',''));
console.log(newArray);
about 4 years ago · Juan Pablo Isaza Relatório

0

What you're looking for is the .map() function. This function iterates over all items in the array, allowing you to execute code on said iterations. Use what I've provided below.

const arrayOfTimestamps = [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ];

const formattedTimestamps = arrayOfTimestamps.map(time => time.replace(/:/g, ''))

As an explanation, .map() iterates over each item, and the time is being handled by regex. the /g aka global flag tells the regex to remove all semicolors's from the strings.

For more information on how .map() works, here.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

about 4 years ago · Juan Pablo Isaza Relatório

0

Although there are other solutions that use less lines of code, the following is easier to read. Loop through your list of dates and for each date, replace the colon character with a blank.

var list = [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ];

for (var i = 0; i < list.length; i++)
{
  list[i] = list[i].replace(':', ''); 
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda